package com.wanglei.eduuserboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wanglei.eduuserboot.entity.User;
import com.wanglei.eduuserboot.mapper.UserMapper;
import com.wanglei.eduuserboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author:wanglei
 * @create:2022-05-24-11:52
 * @Description:
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired   //为什么能注入来着？  知道了，因为有注解扫描
    private UserMapper userMapper;

    @Override
    public User login(String phone, String password) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("phone",phone);
        wrapper.eq("password",password);
        User user = userMapper.selectOne(wrapper);
        return user;
    }

    @Override
    public Integer checkPhone(String phone) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("phone",phone);
        User user = userMapper.selectOne(wrapper);
        if (user == null){
            return 0;
        }
        return 1;
    }

    @Override
    public Integer register(String phone, String password, String nickname, String headimg) {
        User user = new User();
        user.setPhone(phone);
        user.setPassword(password);
        user.setName(nickname);
        user.setPortrait(headimg);
        int insert = userMapper.insert(user);
        return insert;
    }
}
